#include("/common/_layout.html")
#@layout()
#define layoutHead()
	<title>课程列表</title>
#end
#define layoutBody()
	<body>
		<div class="wrap-container clearfix">
				<div class="column-content-detail">
					<div class="layui-form">
						<div class="layui-form-item">
							<div class="layui-inline tool-btn">
								<button class="layui-btn layui-btn-small layui-btn-normal addBtn" data-url="/admin/eduorg/edit/course?app_id=#(login_app_id)&poid=#(ar_poid)"><i class="layui-icon">&#xe654;</i></button>
								<button class="layui-btn layui-btn-small layui-btn-danger delBtn"  data-url="/api/eduorg/course/del" style="display: none;"><i class="layui-icon">&#xe640;</i></button>
							</div>
							<div class="layui-inline" style="display: none;">
								<select id="course_state" name="course_state" lay-filter="course_state">
									<option value="-100" checked>全部</option>
									<option value="1">启用</option>
									<option value="0">禁用</option>
								</select>
							</div>
							<div class="layui-inline">
								<input type="text" id="keywords" name="keywords" placeholder="请输入关键字" autocomplete="off" class="layui-input">
							</div>
							<button class="layui-btn layui-btn-normal" id="btn_search">搜索</button>
						</div>
					</div>
					<div class="layui-form" id="table-list">
						<table class="layui-table" lay-even lay-skin="nob">
							<colgroup>
								<col width="50" style="display:none">
								<col class="hidden-xs" width="50" style="display:none">
								<col>
								<col class="hidden-xs" width="100">
								<col class="hidden-xs" width="100">
								<col class="hidden-xs" width="100">
								<col class="hidden-xs" width="80">
								<col class="hidden-xs" width="160">
								<col width="80">
								<col width="50">
								<col width="120">
							</colgroup>
							<thead>
								<tr>
									<th style="display:none"><input type="checkbox" name="allChoose" lay-skin="primary" lay-filter="allChoose"></th>
									<th class="hidden-xs" style="display:none">ID</th>
									<th>课程名称</th>
									<th class="hidden-xs">课程类型</th>
									<th class="hidden-xs">适合年级</th>
									<th class="hidden-xs">标签</th>
									<th class="hidden-xs">发布</th>
									<th class="hidden-xs">创建时间</th>
									<th class="hidden-xs">状态</th>
									<th class="hidden-xs">详情</th>
									<th class="hidden-xs">操作</th>
								</tr>
							</thead>
							<tbody id="listTbody">
							</tbody>
						</table>
						<div class="page-wrap">
							<div id="divPager"></div>
						</div>
					</div>
				</div>
		</div>
		<!-- #[[ -->
		<script id="tplTbody" type="text/html">
			{{#  layui.each(d.rows, function(index, item){ }}
				<tr>
					<td style="display:none"><input type="checkbox" name="oneChoose" lay-skin="primary" lay-filter="oneChoose" data-id="{{ item.course_id }}"/></td>
					<td class="hidden-xs" style="display:none">{{ item.course_id }}</td>
					<td>{{ item.course_name }}</td>
					<td class="hidden-xs">{{ item.type_name }}</td>
					<td class="hidden-xs">{{ item.grade_name }}</td>
					<td class="hidden-xs">{{ formatNullValue(item.course_tab) }}</td>
					<td class="hidden-xs">
							{{# if (item.power_id === 1) { }}
							公开
							{{# } }}
							{{# if (item.power_id === 0) { }}
							私有
							{{# } }}
					</td>
					<td class="hidden-xs">{{ item.add_time }}</td>
					<td class="hidden-xs">
							{{# if (item.course_state === 1) { }}
							启用
							{{# } }}
							{{# if (item.course_state === 0) { }}
							禁用
							{{# } }}
					</td>
					<td class="hidden-xs">
						<button class="layui-btn  layui-btn-mini layui-btn-primary go-btn" data-id="{{ item.course_id }}" data-url="/admin/eduorg/edit/courseclass?app_id={{ d.app_id }}&poid={{ d.poid }}">详情</button>
					</td>
					<td class="hidden-xs">
						<div class="layui-inline">
							{{# if (item.org_id === d.org_id) { }}
							<button class="layui-btn layui-btn-small layui-btn-normal go-btn" data-id="{{ item.course_id }}" data-url="/admin/eduorg/edit/course?app_id={{ d.app_id }}&poid={{ d.poid }}"><i class="layui-icon">&#xe642;</i></button>
							<button class="layui-btn layui-btn-small layui-btn-danger del-btn" data-id="{{ item.course_id }}" data-url="/api/eduorg/course/del"><i class="layui-icon">&#xe640;</i></button>
							{{# } }}
						</div>
					</td>
				</tr>
			{{#  }); }}
			{{#  if(d.rows.length === 0){ }}
			  无数据
			{{#  } }} 
		</script>
		<!-- ]]# -->
		<script type="text/javascript">
			
		var page_jump_num = 0;
		var initno = 1;
		
		layui.use(['layer', 'laypage', 'laytpl', 'form'], function(){
			var laypage = layui.laypage
			,layer = layui.layer
			,laytpl = layui.laytpl;
			var form = layui.form();
			
			$('#btn_search').click(function(){
				page_jump_num = 0;
				getPageData(1);
			});

			// render pager
			function renderPage(totalPage){
				if (totalPage>0){
					page_jump_num = 0;
					laypage.render({
						elem: 'divPager'
						,count: totalPage
						,limit: global_pagesize
						,jump: function(obj){
							//首次不执行
							if(page_jump_num>0){
								getPageData(obj.curr);
							}
							page_jump_num++;
						}
					});
				}
			}

			// render table
			function renderTable(listData){
				var getTpl = document.getElementById('tplTbody').innerHTML;
				laytpl(getTpl).render(listData, function(html){
					document.getElementById('listTbody').innerHTML = html;
				});
				form.render("checkbox");
			}

			// get page data
			function getPageData(pageNo){
				var surl = "/api/eduorg/course/getPage?pageNo=" + pageNo + "&pageSize=" + global_pagesize+ "&state=" + $('#course_state').val() + "&keywords=" + $('#keywords').val() + "&initno=" + initno + "&poid=" + getUrlParam("poid");
				
				initno++;
				document.getElementById('listTbody').innerHTML = "";
				
				sendPost(surl, null, function(res){
					//console.log(res);
					// 首页，渲染分页
					if (page_jump_num == 0){
						renderPage(res.pageData.totalRow);
					}
					if (res.pageData.list.length>0){
						var jdata = {app_id: #(login_app_id), org_id: #(login_org_id), poid: getUrlParam("poid"), rows: res.pageData.list };
						renderTable(jdata);
					}
				});
			}
			
			getPageData(1);
		});

		
		</script>
	</body>

#end